version 14.2
clear
set more off

*     ****************************************************************  *
*     ****************************************************************  *
*       Filename:       pfp_10_analysis_WGI_selection.do                *
*       Date:           06/03/2017                                      *
*       Author:         Felix Haass, Martin Ottmann                     *
*     ****************************************************************  *
*     ****************************************************************  *



******* OVERVIEW *******
******* (1) load data *******
******* (2) Table 4: OLS regression *******
******* (3) Appendix Figure 8a: interaction b/w cabinetINC and WBnatres_ln *******
******* (4) Appendix Figure 8b: interaction b/w cabinetINC and aid_gdp_ln *******



******* (1) load data *******

use profits_from_peace_replication_dataset.dta, clear



******* (2) postcon5 (selection models): all variables plus interactions *******

* selection model
// first stage is probit, thus cubic splines, cf. Carter & Signorino

etregress WGI_corrupt ///
c.WBnatres_ln c.aid_gdp_ln c.WBDI_gdppc_ln c.WBDI_poptotal_ln c.ethnic c.polity2 ///
if pcy < 6, /// 
treat(cabinetINC = i.parity c.ln_dist_area c.WBnatres_ln c.aid_gdp_ln c.WBDI_gdppc_ln c.WBDI_poptotal_ln c.ethnic c.polity2 c.pcy c.pcy_squared c.pcy_cubed) ///
cluster(gwno)
estimates store selection1

etregress WGI_corrupt c.WBnatres_ln c.cabinetINC#c.WBnatres_ln c.aid_gdp_ln c.WBDI_gdppc_ln c.WBDI_poptotal_ln c.ethnic c.polity2 ///
if pcy < 6, ///
treat(cabinetINC = i.parity c.ln_dist_area c.WBnatres_ln c.aid_gdp_ln c.WBDI_gdppc_ln c.WBDI_poptotal_ln c.ethnic c.polity2 c.pcy c.pcy_squared c.pcy_cubed) ///
cluster(gwno)
estimates store selection2

etregress WGI_corrupt c.aid_gdp_ln c.cabinetINC#c.aid_gdp_ln c.WBnatres_ln c.WBDI_gdppc_ln c.WBDI_poptotal_ln c.ethnic c.polity2 ///
if pcy < 6, ///
treat(cabinetINC = i.parity c.ln_dist_area c.WBnatres_ln c.aid_gdp_ln c.WBDI_gdppc_ln c.WBDI_poptotal_ln c.ethnic c.polity2 c.pcy c.pcy_squared c.pcy_cubed) ///
cluster(gwno)
estimates store selection3

estout selection1 selection2 selection3 ///
, cells(b(star fmt(2)) se(par fmt(2))) starlevels(* 0.10 ** 0.05 *** 0.01) stats(r2 r2_a N, fmt(2 2 0)) legend nobase ///
eqlabels("DV: Control of Corruption" "DV: Executive Power-Sharing")

esttab ///
selection1 selection2 selection3  ///
using manuscript_table_4.tex ///
, b(2) se(2) obslast star(* 0.10 ** 0.05 *** 0.01) nobase ///
order(cabinetINC WBnatres_ln c.cabinetINC#c.WBnatres_ln aid_gdp_ln c.cabinetINC#c.aid_gdp_ln polity2 ethnic WBDI_gdppc_ln WBDI_poptotal_ln) ///
coeflabel(cabinetINC "Executive Power-Sharing" c.cabinetINC#c.WBnatres_ln "Executive PS * Natural Resource Wealth" c.cabinetINC#c.aid_gdp_ln "Executive PS * Foreign Aid Income" parity "Gov't-Rebel Parity") ///
nonumbers mtitles("Model 1" "\Model 2" "Model 3") ///
eqlabels("DV: Control of Corruption" "DV: Executive Power-Sharing") ///
label nogaps nonumbers booktabs fragment ///
replace



******* (3) Appendix Figure 8a: interaction b/w cabinetINC and WBnatres_ln *******

quietly ///
etregress WGI_corrupt ///
c.WBnatres_ln i.cabinetINC#c.WBnatres_ln c.aid_gdp_ln c.WBDI_gdppc_ln c.WBDI_poptotal_ln c.ethnic c.polity2 ///
if pcy < 6, ///
treat(cabinetINC = i.parity c.ln_dist_area c.WBnatres_ln c.aid_gdp_ln c.WBDI_gdppc_ln c.WBDI_poptotal_ln c.ethnic c.polity2 c.pcy c.pcy_squared c.pcy_cubed) ///
cluster(gwno)
quietly margins, dydx(1.cabinetINC) at(WBnatres_ln=(0(.1)4.5) (mean)_c) vsquish
matrix b = r(b)'
matrix list b
matrix b = b[47...,1]
matrix list b
matrix at = r(at)
matrix list at
matrix at = at[1...,"WBnatres_ln"]
matrix list at
matrix v = r(V)
matrix list v
matrix v = v[47...,47...]
matrix list v
matrix se = vecdiag(cholesky(diag(vecdiag(v))))'
matrix list se
matrix d = at,b,se
matrix list d
svmat d, names(d)
generate ul = d2 + 1.96 * d3
generate ll = d2 - 1.96 * d3
clist d1-ll in 1/12
gen yline = 0
graph twoway ///
   (hist WBnatres_ln if pcy < 6, width(0.1) percent color(gs14) yaxis(2) ytitle("Percentage of Observations", axis(2))) ///
   (line d2 d1, clpattern(solid) clwidth(medium) clcolor(black) yaxis(1)) ///
   (line ul d1, clpattern(shortdash) clwidth(thin) clcolor(black)) ///
   (line ll d1, clpattern(shortdash) clwidth(thin) clcolor(black)) ///
   (line yline d1, clwidth(thin) clcolor(black) clpattern(solid)), ///
   xtitle("Natural Resource Wealth (ln)") ///
   ytitle("Conditional Marginal Effect of Executive PS", axis(1)) ///
   ylabel(-1(.5).5) ///
   xlabel(0(1)4.5) ///
   xsize(8) ysize(6) ///
   scheme(lean1) legend(off)
graph export appendix_figure_8a.pdf, replace
drop d1 d2 d3 ul ll yline


******* (4) Appendix Figure 8b: interaction b/w cabinetINC and aid_gdp_ln *******

quietly ///
etregress WGI_corrupt  c.aid_gdp_ln i.cabinetINC#c.aid_gdp_ln c.WBnatres_ln WBDI_gdppc_ln WBDI_poptotal_ln ethnic  polity2 ///
if pcy < 6, ///
treat(cabinetINC = c.ln_dist_area parity c.WBnatres_ln aid_gdp_ln WBDI_gdppc_ln WBDI_poptotal_ln ethnic polity2 pcy pcy_squared pcy_cubed) ///
cluster(gwno)
quietly margins, dydx(1.cabinetINC) at(aid_gdp_ln=(-11(.2)1) (mean)_c) vsquish
matrix b = r(b)'
matrix list b
matrix b = b[62...,1]
matrix list b
matrix at = r(at)
matrix list at
matrix at = at[1...,"aid_gdp_ln"]
matrix list at
matrix v = r(V)
matrix list v
matrix v = v[62...,62...]
matrix list v
matrix se = vecdiag(cholesky(diag(vecdiag(v))))'
matrix list se
matrix d = at,b,se
matrix list d
svmat d, names(d)
generate ul = d2 + 1.96 * d3
generate ll = d2 - 1.96 * d3
clist d1-ll in 1/12
gen yline = 0
graph twoway ///
   (hist aid_gdp_ln if pcy < 6, width(0.3) percent color(gs14) yaxis(2) ytitle("Percentage of Observations", axis(2))) ///
   (line d2 d1, clpattern(solid) clwidth(medium) clcolor(black) yaxis(1)) ///
   (line ul d1, clpattern(shortdash) clwidth(thin) clcolor(black)) ///
   (line ll d1, clpattern(shortdash) clwidth(thin) clcolor(black)) ///
   (line yline d1, clwidth(thin) clcolor(black) clpattern(solid)), ///
   xtitle("Foreign Aid Income (ln)") ///
   ytitle("Conditional Marginal Effect of Executive PS", axis(1)) ///
   ylabel(-3(.5)1) ///
   xlabel(-11(2)1) ///
   xsize(8) ysize(6) ///
   scheme(lean1) legend(off)
graph export appendix_figure_8b.pdf, replace
drop d1 d2 d3 ul ll yline
